/*
package com.jymj.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.jymj.common.annotation.SysLog;
import com.jymj.entity.RtInvestEntity;
import com.jymj.entity.gantt.PjTaskEntity;
import com.jymj.entity.view.RtInvestTask;
import com.jymj.service.RtInvestService;
import com.jymj.utils.ParseUtils;
import com.jymj.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

*/
/**
 * Created by dl on 2017/10/18. 支付情况
 *//*

@RestController
@RequestMapping("/invest")
@Transactional(rollbackFor = Exception.class)
public class RtInvestController {

    private final Logger LOGGER = LoggerFactory.getLogger(RtInvestController.class);
    @Autowired
    private RtInvestService rtInvestService;

    ParseUtils parseUtils = new ParseUtils();

    */
/**
     * 投资测算表
     *
     * @param pid
     * @param request
     * @param response
     * @return R
     * @throws Exception
     *//*

    @RequestMapping("/invest/{pid}")
    public R invest(@PathVariable("pid") Integer pid, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("pid", pid);
        List<RtInvestTask> list = rtInvestService.queryList(map);
        List<RtInvestTask> treeList = this.getTreeOrgs(list);
        return R.ok().put("data", treeList);
    }

    */
/**
     * 更新投资测算表 by ljj 2017-10-16
     *
     * @param investEntity
     * @return R
     *//*

    @SysLog("新增/更新投资测算表")
    @RequestMapping("/updateInvest")
    public R updateInvest(@RequestBody RtInvestEntity investEntity) {
        if (investEntity.getPid() != null && investEntity.getCostid() != null) {
            //判断投资计划表是否有数据
            if (investEntity.getId() == null || "".equals(investEntity.getId())) {
                rtInvestService.save(investEntity);
            } else {
                rtInvestService.update(investEntity);
            }
            rtInvestService.updateParentCost(investEntity);
            //修改总价
            rtInvestService.updateZj(investEntity.getPid());

        }
        return R.ok();
    }

    */
/**
     * 获取测算唯一对象 by DL
     *
     * @param investId
     * @return
     *//*

    @RequestMapping("/getInvest/{investId}")
    public R getInvest(@PathVariable("investId") Integer investId) {
        RtInvestEntity r = rtInvestService.queryObject(investId);
        return R.ok().put("invest", r);
    }

    @RequestMapping("/investWithChilds/{pid}")
    public void investWithChilds(@PathVariable("pid") Integer pid, HttpServletRequest request,
            HttpServletResponse response) {
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("pid", pid);
            List<RtInvestEntity> list = rtInvestService.queryListWithChild(map);
            SimplePropertyPreFilter filter = new SimplePropertyPreFilter(PjTaskEntity.class, "id", "itemid", "itemname",
                    "cost", "parentid", "orderid", "remark");
            map = new HashMap<>();
            map.put("data", list);
            //SerializeFilter[] filters = {nameFilter, filter};
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF-8");
            response.getWriter().print(JSON.toJSONString(map, filter));
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }

    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable("id") int id) {
        rtInvestService.deleteById(id);
        return R.ok();
    }

    public List<RtInvestTask> getTreeOrgs(List<RtInvestTask> allOrgs) throws Exception {
        List<RtInvestTask> listParentRecord = new ArrayList<>();
        List<RtInvestTask> listNotParentRecord = new ArrayList<>();
        // 第一步：遍历allOrgs找出所有的根节点和非根节点
        if (allOrgs != null && allOrgs.size() > 0) {
            allOrgs.forEach((org) -> {
                if (0 == org.getPtfatherid()) {
                    listParentRecord.add(org);
                } else {
                    listNotParentRecord.add(org);
                }
            });
        }
        // 第二步： 递归获取所有子节点
        if (listParentRecord.size() > 0) {
            for (RtInvestTask record : listParentRecord) {
                // 添加所有子级
                record.setChildren(this.getChildOrgs(listNotParentRecord, record.getPttaskid()));
            }
        }
        return listParentRecord;
    }

    public List<RtInvestTask> getChildOrgs(List<RtInvestTask> childList, Integer ptfatherid) throws Exception {
        List<RtInvestTask> listParentOrgs = new ArrayList<>();
        List<RtInvestTask> listNotParentOrgs = new ArrayList<>();
        // 遍历childList，找出所有的根节点和非根节点
        if (childList != null && childList.size() > 0) {
            childList.forEach((record) -> {
                // 对比找出父节点
                if (record.getPtfatherid().equals(ptfatherid)) {
                    listParentOrgs.add(record);
                } else {
                    listNotParentOrgs.add(record);
                }
            });
        }
        // 查询子节点
        if (listParentOrgs.size() > 0) {
            for (RtInvestTask record : listParentOrgs) {
                // 递归查询子节点
                record.setChildren(getChildOrgs(listNotParentOrgs, record.getPttaskid()));
            }
        }
        return listParentOrgs;
    }

    */
/*
    * 投资测算列表
    * *//*

    @RequestMapping("/rtInvest/{pid}")
    public R rtInvest(@PathVariable("pid") Integer pid, HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("pid", pid);
        List<RtInvestEntity> list = rtInvestService.queryRtInvestList(map);
        List<RtInvestEntity> treeList = this.getTreeRt(list);
        return R.ok().put("data", treeList);
    }

    public List<RtInvestEntity> getTreeRt(List<RtInvestEntity> allOrgs) throws Exception {
        List<RtInvestEntity> listParentRecord = new ArrayList<>();
        List<RtInvestEntity> listNotParentRecord = new ArrayList<>();
        // 第一步：遍历allOrgs找出所有的根节点和非根节点
        if (allOrgs != null && allOrgs.size() > 0) {
            allOrgs.forEach((org) -> {
                if (0 == org.getParentid()) {
                    listParentRecord.add(org);
                } else {
                    listNotParentRecord.add(org);
                }
            });
        }
        // 第二步： 递归获取所有子节点
        if (listParentRecord.size() > 0) {
            for (RtInvestEntity record : listParentRecord) {
                // 添加所有子级
                record.setChildren(this.getChildOrgs1(listNotParentRecord, record.getItemid()));
            }
        }
        return listParentRecord;
    }

    public List<RtInvestEntity> getChildOrgs1(List<RtInvestEntity> childList, Integer itemid) throws Exception {
        List<RtInvestEntity> listParentOrgs = new ArrayList<>();
        List<RtInvestEntity> listNotParentOrgs = new ArrayList<>();
        // 遍历childList，找出所有的根节点和非根节点
        if (childList != null && childList.size() > 0) {
            childList.forEach((record) -> {
                // 对比找出父节点
                if (record.getParentid().equals(itemid)) {
                    listParentOrgs.add(record);
                } else {
                    listNotParentOrgs.add(record);
                }
            });
        }
        // 查询子节点
        if (listParentOrgs.size() > 0) {
            for (RtInvestEntity record : listParentOrgs) {
                // 递归查询子节点
                record.setChildren(getChildOrgs1(listNotParentOrgs, record.getItemid()));
            }
        }
        return listParentOrgs;
    }

    */
/* * 修改子级
    * *//*

    @RequestMapping("/updateRtInvest")
    public R updateRtInvest(@RequestBody RtInvestEntity rtInvestEntity) {
        if (rtInvestEntity.getPid() != null) {
            if (rtInvestEntity.getId() == null) {
                rtInvestService.saveRtInvest(rtInvestEntity);
            } else {
                rtInvestService.updateRtInvest(rtInvestEntity);
            }
            rtInvestService.updateRtInvestCost(rtInvestEntity);
        }
        return R.ok();
    }
}
*/
